﻿namespace CardManagement
{
    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class FormCardHas : Form
    {
        public string cardpath = (Application.StartupPath + @"\CardPath.json");
        private IContainer components = null;
        private SplitContainer splitContainer1;
        private DataGridView dgvM;
        private Button buttonDel;

        public FormCardHas()
        {
            this.InitializeComponent();
            this.cardHas = this.GetCardHas();
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            try
            {
                Cards row = this.dgvM.CurrentRow.DataBoundItem as Cards;
                this.cardHas = (from o in this.cardHas
                    where o.CardNo != row.CardNo
                    select o).ToList<Cards>();
                this.dgvM.DataSource = this.cardHas;
                FileHelper.TxtWrite(this.cardpath, JsonConvert.SerializeObject(this.cardHas));
            }
            catch
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FormCardHas_Load(object sender, EventArgs e)
        {
            this.dgvM.DataSource = this.cardHas;
        }

        public List<Cards> GetCardHas()
        {
            List<Cards> list2;
            string str = FileHelper.TxtRead(this.cardpath);
            if (!string.IsNullOrEmpty(str))
            {
                list2 = JsonConvert.DeserializeObject<List<Cards>>(str);
            }
            else
            {
                List<Cards> list = new List<Cards>();
                FileHelper.TxtWrite(this.cardpath, JsonConvert.SerializeObject(list));
                list2 = list;
            }
            return list2;
        }

        private void InitializeComponent()
        {
            this.splitContainer1 = new SplitContainer();
            this.dgvM = new DataGridView();
            this.buttonDel = new Button();
            this.splitContainer1.BeginInit();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            ((ISupportInitialize) this.dgvM).BeginInit();
            base.SuspendLayout();
            this.splitContainer1.Dock = DockStyle.Fill;
            this.splitContainer1.FixedPanel = FixedPanel.Panel2;
            this.splitContainer1.Location = new Point(0, 0);
            this.splitContainer1.Name = "splitContainer1";
            this.splitContainer1.Orientation = Orientation.Horizontal;
            this.splitContainer1.Panel1.Controls.Add(this.dgvM);
            this.splitContainer1.Panel2.Controls.Add(this.buttonDel);
            this.splitContainer1.Size = new Size(0x203, 0x137);
            this.splitContainer1.SplitterDistance = 0x10c;
            this.splitContainer1.TabIndex = 0;
            this.dgvM.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvM.Dock = DockStyle.Fill;
            this.dgvM.Location = new Point(0, 0);
            this.dgvM.Name = "dgvM";
            this.dgvM.RowTemplate.Height = 0x17;
            this.dgvM.Size = new Size(0x203, 0x10c);
            this.dgvM.TabIndex = 0;
            this.buttonDel.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.buttonDel.Location = new Point(0x19d, 4);
            this.buttonDel.Name = "buttonDel";
            this.buttonDel.Size = new Size(90, 30);
            this.buttonDel.TabIndex = 1;
            this.buttonDel.Text = "删除记录";
            this.buttonDel.UseVisualStyleBackColor = true;
            this.buttonDel.Click += new EventHandler(this.buttonDel_Click);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x203, 0x137);
            base.Controls.Add(this.splitContainer1);
            base.Name = "FormCardHas";
            this.Text = "本地卡号管理";
            base.Load += new EventHandler(this.FormCardHas_Load);
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.EndInit();
            this.splitContainer1.ResumeLayout(false);
            ((ISupportInitialize) this.dgvM).EndInit();
            base.ResumeLayout(false);
        }

        public List<Cards> cardHas { get; set; }
    }
}

